const createPlateRecently = (function () {
  /**
   * 格式化时间到 YYYY.MM.DD
   * @param {number} time 
   */
  function fmtTime(time) {
    const d = new Date(time);
    return `${d.getFullYear()}.${d.getMonth() + 1}.${d.getDate()}`
  }

  /**
   * 生成一个节点Dom
   * @param {RecentlyItem} param0 
   */
  function initItem({ title, time, comment, id }) {
    const $item = document.createElement('li');
    $item.innerHTML = `
    <a href="${id}.html">
      <span class="plate-recently-name">${title}</span>
      <span class="plate-recently-time">${fmtTime(time)}</span>
      <span class="plate-recently-comment">${comment}</span>
    </a>`
    return $item;
  }

  const $recently = document.getElementById('plate-recently-list');
  /**
   * @typedef {{title: string, time: number, comment: string, id: string}} RecentlyItem
   * @param {RecentlyItem[]} items
   */
  function init(items) {
    items.forEach(item =>
      $recently.appendChild(initItem(item)))
  }
  return init
})()